package com.dtagri.fjwlw.fragment;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;

import com.dtagri.fjwlw.AppContext;
import com.dtagri.fjwlw.R;
import com.dtagri.fjwlw.adapter.MonitoringAlarmAdapter;
import com.dtagri.fjwlw.api.FJwlwApi;
import com.dtagri.fjwlw.base.BaseSimpleActivity;
import com.dtagri.fjwlw.base.BaseSimpleFragment;
import com.dtagri.fjwlw.base.TGson;
import com.dtagri.fjwlw.bean.SmallArea;
import com.dtagri.fjwlw.bean.TjAreaMsg;
import com.dtagri.fjwlw.bean.TjCompanyRegion;
import com.dtagri.fjwlw.widget.EmptyLayout;
import com.google.gson.reflect.TypeToken;

/**
 * 监测报警
 * 
 * @author wxjn
 * 
 */
public class MonitoringAlarmFragment extends BaseSimpleFragment {
	protected ListView listView;

	private MonitoringAlarmAdapter monitoringAlarmAdapter;

	protected List<TjAreaMsg> tjAreaMsgs = new ArrayList<TjAreaMsg>();
	

	@Override
	protected void xOnSuccess(byte[] arg2) {
		Type type = new TypeToken<List<TjAreaMsg>>() {
		}.getType();
		tjAreaMsgs = TGson.gson.fromJson(new String(arg2), type);
		if(tjAreaMsgs.size()==0){
			baseSimpleActivity.getmErrorLayout().setErrorType(
					EmptyLayout.NODATA);
			baseSimpleActivity.getmErrorLayout().setErrorMessage("暂无数据");
		}
		monitoringAlarmAdapter = new MonitoringAlarmAdapter(getActivity(),
				tjAreaMsgs);
		listView.setAdapter(monitoringAlarmAdapter);
		
	}

	@Override
	public void initView(View view) {
		super.initView(view);
		
		listView = (ListView) view.findViewById(R.id.listview);
		
	}

	@Override
	protected void xInitData() {
		baseSimpleActivity.getmErrorLayout().setErrorMessage("加载监测数据中…");
		TjCompanyRegion tjCompanyRegion = AppContext.user.getTjCompanyRegions()
				.get(AppContext.userOperate.getCurBaseIndex());
		FJwlwApi.alarmData(tjCompanyRegion.getRegionId(),
				AppContext.user.getCompanyId() + "", mHandler);
	}

	@Override
	protected int getLayoutId() {
		return R.layout.layout_simple_list;
	}

	@Override
	protected String getCacheKey() {
		return "alarmData";
	}
}
